<?php
require_once('../../libraryfiles/config.php');
$include = '
<link rel="stylesheet" href="'.W_ROOT.'/css/admin_style.css" />
<script type="text/javascript" src="'.W_ROOT.'/js/action.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/common.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
';
$view = (isset($_GET['view'])) ? $_GET['view'] : '';
switch ($view) {
	//this is case for adding banner
	case'add':
		if (isset($_GET['id'])) {
			$id = (int) $_GET['id'];
		} else if (isset($_POST['id'])) {
			$id = $_POST['id'][0];
		}
		else
		$id = 0;

		$site_title = "Administrator Site - Add New Banner";
		$content = 'add.php';
		break;
		//this is case for delete banner
	case 'delete':
		if (isset($_GET['view']) && $_GET['view'] == 'delete') {
			$id = $_GET['id'];
			$image = '';
			$img = mysql_query("SELECT *FROM tbl_banner WHERE ban_id=" . $id);
			while ($arr = mysql_fetch_array($img)) {
				$image = $arr['ban_img_upload'];
			}
			if (file_exists('../../images/banners/' . $image)) {
				unlink('../../images/banners/' . $image);
			}
			$sql = "DELETE FROM tbl_banner WHERE ban_id=$id";
			mysql_query($sql);
			header('Location:'.base_url_admin.'/banner/index.php?message=delete');
			exit();
		}
		break;
		//this is case for edit banner
	case'edit':
		if (isset($_GET['id'])) {
			$id = (int) $_GET['id'];
		} else if (isset($_POST['id'])) {
			$id = $_POST['id'][0];
		}
		else
		$id = 0;

		$site_title = "Administrator Site - Edit Banner";
		$content = 'formedit.php';
		break;
		//this is case for publish banner
	case 'publish' :
		if (isset($_GET['id']) && (int) $_GET['id'] > 0) {
			$id = (int) $_GET['id'];
		} else {
			header('Location:index.php');
			exit();
		}

		if (isset($_GET['publish']) && (int) $_GET['publish'] >= 0 && (int) $_GET['publish'] <= 1) {
			$publish = (int) $_GET['publish'];
		} else {
			header('Location: index.php');
			exit();
		}

		//Statement to publish/unpublish User
		publishBanner('tbl_banner', $publish, $id);

		//header("Location: index.php?" . getAllGetParams(array('view', 'id', 'publish'))); //page=".$page."&");
		header("Location: index.php?");
		exit();
		break;

	case 'unpublish' :
		mysql_query("UPDATE tbl_banner SET ban_status=0 WHERE ban_id=" . $_GET['id']);

		echo '<p style="color:#FF0000" align="center">Banner have been blocked!<a href="#" onClick="history.go(-1)">Back</a></p>';

	default:
		$site_title = "Administrator Site - Banner";
		$content = 'list.php';
		break;
}

require_once TMP_ADMIN_PATH;
?>